package test.study.concurrent.thread._2_executor.scheduled;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
public class _1_ScheduledThreadPoolExecutor_Main {

    private static ScheduledExecutorService POOL = new ScheduledThreadPoolExecutor(10);

    /**
     * 调度一次
     *
     * @param command Runnable
     * @param delay   long
     * @param unit    TimeUnit
     */
    public static void main(String[] args) {
        Runtime r = Runtime.getRuntime();
        r.availableProcessors();
        log.info("主线程开始");

        //Step-1:
        ScheduledFuture future = POOL.schedule(() -> {
            log.info("fffadsfasdf");
        }, 5, TimeUnit.SECONDS);
        //Step-2:
        try {
            Object i = future.get();
            log.info(">>>>>> {}", i);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        log.info("主线程结束");
    }
}
